package com.pi.smart.wxmini.controller;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.pi.base.dto.result.AppResult;
import com.pi.cs.enumerate.ContactWay;
import com.pi.cs.enumerate.FeedType;
import com.pi.cs.model.FeedBackPostForm;
import com.pi.cs.model.vo.SmartBedFeedBackVo;
import com.pi.cs.service.FeedBackService;
import com.pi.http.base.controller.BaseController;

@RequestMapping("/counter")
@RestController
public class SmartCounterController extends BaseController{

  @Autowired
  private FeedBackService feedBackService;
  @PostMapping("/feed")
  public AppResult addFeedBack(FeedBackPostForm form){
    form.setType(FeedType.COMM_ADVICE.getType());
    form.setContactWay(ContactWay.EMAIL.getType());
    if(StringUtils.isBlank(form.getPics()))
      form.setPics(StringUtils.EMPTY);
    form.setRequestUser(getLoginUserId());
    if(StringUtils.isBlank(form.getContact()))
      form.setContact(StringUtils.EMPTY);
    feedBackService.addFeedBack(form);
    return AppResult.OK;
  }
  
  @GetMapping("/feed")
  public AppResult queryFeedBack(){
    List<SmartBedFeedBackVo> feedVo = 
        feedBackService.queryUserFeedVO(getLoginUserId());
    return AppResult.newSuccessResult(feedVo);
  }
}
